library(ggplot2)

load("data/Accountability_PartyInstitutionalization.RData")

# Japan China 2012 (biggest territorial dispute took place)
china_acc <- subset$v2x_accountability[subset$year == 2012 & subset$cname == "China"]
japan_acc <- subset$v2x_accountability[subset$year == 2012 & subset$cname == "Japan"]
china_party <- subset$v2xps_party[subset$year == 2012 & subset$cname == "China"]
japan_party <- subset$v2xps_party[subset$year == 2012 & subset$cname == "Japan"]

# each dot represents one country-year observation between 1946 and 2017
china_japan <- ggplot(subset, aes(x = v2x_accountability, y = v2xps_party)) + geom_point(size = 2,alpha = 0.1, color = "grey") +
  scale_alpha(guide = 'none') + guides(colour = guide_legend(override.aes = list(alpha = 1)))+
  xlab("Government Accountability")+
  ylab("Party Institutionalization")+
  geom_smooth(color = "black") + geom_rug(sides="b", alpha=0.15, size=0.25) + 
  annotate(geom="text", x=1.8, y=1.1, label= paste("Corr = ", round(cor(subset$v2x_accountability, 
                                                                        subset$v2xps_party, use = "complete.obs"),
                                                                    digits = 2), sep =""),
           color="black", size = 3.5) + 
  theme_bw() +
  theme(text = element_text(size=15)) +
  annotate("point", x = china_acc, y = china_party, colour = "black", size = 3) +
  annotate("text", x = china_acc, y = china_party * 1.05, label = "China (2012)", size = 5.5) +
  annotate("point", x = japan_acc, y = japan_party, colour = "black", size = 3) +
  annotate("text", x = japan_acc * 1.1, y = japan_party * 0.96, label = "Japan (2012)", size = 5.5)

pdf("figs/Fig.1.pdf", width = 9, height = 6.5)
china_japan
dev.off()